﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BYUStock
{
    public partial class WebCrawler : Form
    {
        public WebCrawler()
        {
            InitializeComponent();
        }

        Uri URI;
        WebClient Client = new WebClient();
        string MyEncoding = "GB2312";
        private void tbx_URL_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar != (char)Keys.Enter) return;
            URI = new Uri(tbx_URL.Text.Trim().ToLower());
            webBrowser1.Url = URI;
            webBrowser1.Show();
            byte[] bytes = Client.DownloadData(URI);
            string content = Encoding.GetEncoding(MyEncoding).GetString(bytes);
            rtbx_Content.Clear();
            rtbx_Content.Text = content;
        }

        private void comboBox1_Click(object sender, EventArgs e)
        {
        }

        private void comboBox1_TextChanged(object sender, EventArgs e)
        {
            MyEncoding = comboBox1.Text;
            byte[] bytes = Client.DownloadData(URI);
            string content = Encoding.GetEncoding(MyEncoding).GetString(bytes);
            rtbx_Content.Clear();
            rtbx_Content.Text = content;
        }
    }
}
